window.addEventListener("load", function () {
	// 遍历输入框
	const regex2 = /^[a-zA-Z0-9]{6,20}$/;
	// 手机号
	const regex =
		/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
	// 密码
	const regex3 = /^\w{3,12}$/;
	//获取节点表单节点
	// 用户名
	const numeralList = document.querySelector("#numeral");
	//手机号
	const nomeList = document.querySelector("#nome");
	//密码
	const passwoodList = document.querySelector("#passwood");
	//brn按钮
	const btnList = document.querySelector("#btn");
	console.log(numeralList, nomeList, passwoodList, btnList); //打印看一下拿到节点没有
	//2.给btn绑定点击事件
	btnList.addEventListener("click", function (e) {
		//拿到input的值
		let numeralListValue = numeralList.value;
		let nomeListValue = nomeList.value;
		let passwoodListValue = passwoodList.value;
		// console.log(numeralListValue, nomeListValue, passwoodListValue);
		// 用户名
		if (regex2.test(numeralListValue)) {
			numeralList.nextElementSibling.textContent = "";
			numeralList.nextElementSibling.style.color = "";
			numeralList.style.border = "";
		} else {
			numeralList.nextElementSibling.textContent = "呢称在6-12位字母数字间";
			numeralList.nextElementSibling.style.color = "red";
			numeralList.style.border = "1px solid red";
		}
		//手机号
		if (regex.test(nomeListValue)) {
			nomeList.nextElementSibling.textContent = "";
			nomeList.nextElementSibling.style.color = "";
			nomeList.style.border = "";
		} else {
			nomeList.nextElementSibling.textContent = "请输入11位手机号";
			nomeList.nextElementSibling.style.color = "red";
			nomeList.style.border = "1px solid red";
		}
		//密码框
		if (regex3.test(passwoodListValue)) {
			passwoodList.nextElementSibling.textContent = "";
			passwoodList.style.border = "";
		} else {
			passwoodList.nextElementSibling.textContent = "请输入3到12位的密码";
			passwoodList.nextElementSibling.style.color = "red";
			passwoodList.style.border = "1px solid red";
		}
		e.preventDefault(); //阻止默认事件提交
	});
	//获取验证码
	const buttonList = document.querySelector("#button");
	buttonList.addEventListener("click", function () {
		let num = 10;
		let time = setInterval(function () {
			//禁用
			buttonList.disabled = true;
			buttonList.textContent = `${num}秒后重新发送`;
			num--;
			// 关闭定时器
			if (num < 0) {
				//关闭定时器
				clearInterval(time);
				buttonList.disabled = false;
				buttonList.textContent = "点击重新发送";
			}
		}, 1000);
	});
});
